package com.example.mobile2021606163crw0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tv_main_title;
    private RadioGroup radGup_car_type;
    private RadioButton radBtn_main_saloon;
    private RadioButton radBtn_main_MPV;
    private RadioButton radBtn_main_SUV;
    private RadioGroup radGup_main_line;
    private RadioButton radBtn_main_line1;
    private RadioButton radBtn_main_line2;
    private RadioButton radBtn_main_line3;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGup_car_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("radioButton", radioButton.getText().toString());
                String r1 = radioButton.getText().toString();
                Toast.makeText(MainActivity.this,"车型为"+r1,Toast.LENGTH_SHORT).show();
            }
        });
        radGup_main_line.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("radioButton", radioButton.getText().toString());
                String r2 = radioButton.getText().toString();
                Toast.makeText(MainActivity.this,"车间为"+r2,Toast.LENGTH_SHORT).show();
            }
        });
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int carID = radGup_car_type.getCheckedRadioButtonId();
                if (carID!=-1){
                    RadioButton radioButton = findViewById(carID);
                    Log.i("TAG", radioButton.getText().toString());
                    new AlertDialog.Builder(MainActivity.this)
                            .setMessage("创建成功")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }else {
                    Log.i("TAG", "未选中车型以及车间");
                    new AlertDialog.Builder(MainActivity.this)
                            .setMessage("未选中车型以及车间")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }

            }
        });
    }

    private void initView() {
        tv_main_title = (TextView) findViewById(R.id.tv_main_title);
        radGup_car_type = (RadioGroup) findViewById(R.id.radGup_car_type);
        radBtn_main_saloon = (RadioButton) findViewById(R.id.radBtn_main_saloon);
        radBtn_main_MPV = (RadioButton) findViewById(R.id.radBtn_main_MPV);
        radBtn_main_SUV = (RadioButton) findViewById(R.id.radBtn_main_SUV);
        radGup_main_line = (RadioGroup) findViewById(R.id.radGup_main_line);
        radBtn_main_line1 = (RadioButton) findViewById(R.id.radBtn_main_line1);
        radBtn_main_line2 = (RadioButton) findViewById(R.id.radBtn_main_line2);
        radBtn_main_line3 = (RadioButton) findViewById(R.id.radBtn_main_line3);
        btn = (Button) findViewById(R.id.btn);
    }
}